<template>
  <div class="goods-list-item">
    <img :src="getImageUrl" alt="" @load="goodsItemLoad" @click="goodsItemClick"/>
    <div class="goods-info">
      <p class="title">{{ goodsItem.title }}</p>
      <span class="price">{{ goodsItem.price }}</span>
      <span class="collect">{{ goodsItem.cfav }}</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  created() {},
  mounted() {},
  methods: {
    goodsItemLoad(){
       this.$bus.$emit("goodsItemLoad");
    },
    goodsItemClick(){
      this.$router.push({
          path: '/detail',
          query: {
            iid: this.goodsItem.iid 
          }
        })
    }
  },
  computed: {
    getImageUrl() {
      if (this.goodsItem.show) {
        return this.goodsItem.show.img;
      } else if (this.goodsItem.image) {
        return this.goodsItem.image;
      } else {
        return this.goodsItem.img;
      }
    },
  },
};
</script>

<style scoped lang="scss">
.goods-list-item {
  width: 47%;
  margin: 5px 0;
  img {
    width: 100%;
    border-radius: 5px;
  }
}

.goods-info {
  text-align: center;
  overflow: hidden;
  font-size: 12px;
  .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
  }
  .price{
      color: #FF8198;
      margin-right: 30px;
  }
  .collect{
     position: relative;
  }
  .collect::before{
    content: '';
    position: absolute;
    left: -15px;
    top: -1px;
    width: 14px;
    height: 14px;
    background: url("~assets/img/common/collect.svg") 0 0/14px 14px;
  }
}
</style>
